﻿using DigitalQuran.Statistic;
using System.Collections.Generic;

namespace DigitalQuran.Numerology {
    
    /// <summary>
    /// Represent a Numerology System
    /// </summary>
    public abstract class NumerologySystem : Dictionary<char, long> {
        
        /// <summary>
        /// Gets Unique Name of System
        /// </summary>
        internal string UniqueName { get; set; }

        internal virtual void Update(LetterStatisticTable stat, string textMode) {

            this.TextMode = textMode;

            var v = GetValues();
            int count = stat.Count, i = 0;
            for (; i < count && v.MoveNext(); i++) {
                this.Add(stat[i].Letter, v.Current);
            }

            for (; i < count; i++)
                this.Add(stat[i].Letter, 0);			
        }

        /// <summary>
        /// Gets Text Mode
        /// </summary>
        public string TextMode { get; internal set; }

        /// <summary>
        /// Register the Numerology System
        /// </summary>
        /// <param name="uniqueName"></param>
        public void Register(string uniqueName) {
            this.UniqueName = uniqueName;
            if (Client.Instance != null) {
                Client.Instance.Numerology.Add(uniqueName, this);
            }
        }

        public abstract IEnumerator<long> GetValues();
    }
}